<div class="container-fluid my-3">
  <h2>
    {{ get_icon('b_routines', t('Routines')) }}
    {{ show_mysql_docu('STORED_ROUTINES') }}
  </h2>

  <div class="d-flex flex-wrap my-3">
    {%- if has_any_routines %}
    <div>
      <div class="input-group">
        <div class="input-group-text">
          <div class="form-check mb-0">
            <input class="form-check-input checkall_box" type="checkbox" value="" id="checkAllCheckbox" form="rteListForm">
            <label class="form-check-label" for="checkAllCheckbox">{{ t('Check all') }}</label>
          </div>
        </div>
        <button class="btn btn-outline-secondary" id="bulkActionExportButton" type="submit" name="submit_mult" value="export" form="rteListForm" title="{{ t('Export') }}">
          {{ get_icon('b_export', t('Export')) }}
        </button>
        <button class="btn btn-outline-secondary" id="bulkActionDropButton" type="submit" name="submit_mult" value="drop" form="rteListForm" title="{{ t('Drop') }}">
          {{ get_icon('b_drop', t('Drop')) }}
        </button>
      </div>
    </div>

    <div class="ms-auto">
      <div class="input-group">
        <span class="input-group-text">{{ get_image('b_search', t('Search')) }}</span>
        <input class="form-control" name="filterText" type="text" id="filterText" value="" placeholder="{{ t('Search') }}" aria-label="{{ t('Search') }}">
      </div>
    </div>
    {%- endif %}

    <div{{ has_any_routines ? ' class="ms-2"' }}>
      <a class="ajax add_anchor btn btn-primary{{ not has_privilege ? ' disabled' }}" href="{{ url('/database/routines', {'db': db, 'table': table, 'add_item': true}) }}" role="button"{{ not has_privilege ? ' tabindex="-1" aria-disabled="true"' }}>
        {{ get_icon('b_routine_add', t('Create new routine')) }}
      </a>
    </div>
  </div>

  {%- if has_any_routines -%}
    {{ list_navigator_html|raw }}
  {%- endif -%}

  <form id="rteListForm" class="ajax" action="{{ url('/database/routines') }}">
    {{ get_hidden_inputs(db, table) }}

    <div id="nothing2display"{{ has_any_routines ? ' class="hide"' }}>
      {{ t('There are no routines to display.')|notice }}
    </div>

    <table id="routinesTable" class="table table-striped table-hover{{ not has_any_routines ? ' hide' }} data w-auto">
      <thead>
      <tr>
        <th></th>
        <th>{{ t('Name') }}</th>
        <th>{{ t('Type') }}</th>
        <th>{{ t('Returns') }}</th>
        <th colspan="4"></th>
      </tr>
      </thead>
      <tbody>
      <tr class="hide">{% for i in 0..7 %}<td></td>{% endfor %}</tr>

      {{- rows|raw }}
      </tbody>
    </table>
  </form>

  {%- if has_any_routines -%}
    {{ list_navigator_html|raw }}
  {%- endif -%}

  <div class="modal fade" id="routinesEditorModal" tabindex="-1" aria-labelledby="routinesEditorModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-xl modal-dialog-scrollable">
      <div class="modal-content">
        <div class="modal-header">
          <h1 class="modal-title fs-5" id="routinesEditorModalLabel">{{ t('Routine editor') }}</h1>
          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="{{ t('Close') }}"></button>
        </div>
        <div class="modal-body">
          <div class="spinner-border" role="status">
            <span class="visually-hidden">{{ t('Loading…') }}</span>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{{ t('Close') }}</button>
          <button type="button" class="btn btn-primary" id="routinesEditorModalSaveButton">{{ t('Save changes') }}</button>
        </div>
      </div>
    </div>
  </div>

  <div class="modal fade" id="routinesExportModal" tabindex="-1" aria-labelledby="routinesExportModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-xl">
      <div class="modal-content">
        <div class="modal-header">
          <h1 class="modal-title fs-5" id="routinesExportModalLabel">{{ t('Export routine') }}</h1>
          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="{{ t('Close') }}"></button>
        </div>
        <div class="modal-body"></div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{{ t('Close') }}</button>
        </div>
      </div>
    </div>
  </div>

  <div class="modal fade" id="routinesExecuteModal" tabindex="-1" aria-labelledby="routinesExecuteModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-xl modal-dialog-scrollable">
      <div class="modal-content">
        <div class="modal-header">
          <h1 class="modal-title fs-5" id="routinesExecuteModalLabel">{{ t('Execute routine') }}</h1>
          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="{{ t('Close') }}"></button>
        </div>
        <div class="modal-body">
          <div class="spinner-border" role="status">
            <span class="visually-hidden">{{ t('Loading…') }}</span>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{{ t('Close') }}</button>
          <button type="button" class="btn btn-primary" id="routinesExecuteModalExecuteButton">{{ t('Execute') }}</button>
        </div>
      </div>
    </div>
  </div>
</div>
